package com.cxh.rmsq.ui.adapter.self

import android.content.Intent
import android.text.TextUtils
import androidx.core.view.isVisible
import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cxh.rmsq.R
import com.cxh.rmsq.common.IntentExtra
import com.cxh.rmsq.db.model.CommunityContent
import com.cxh.rmsq.ui.activity.self.LookUserDetailActivity2
import com.cxh.rmsq.ui.widget.SelectableRoundedImageView
import com.cxh.rmsq.utils.loadImage
import com.hjq.shape.view.ShapeTextView


/**
 *
 */
class FansListAdapter(type: Int) :
    BaseQuickAdapter<CommunityContent, BaseViewHolder>(R.layout.item_fans_list),
    LoadMoreModule {

    init {
        addChildClickViewIds(R.id.stv_focus)
    }

    var type = type  //1订阅 2粉丝
    private var mData = mutableListOf<String>() //图片

    override fun convert(holder: BaseViewHolder, item: CommunityContent) {
        with(holder) {

            setText(R.id.tv_name, item.nickname)
            if (type == 1) {
                holder.getView<ShapeTextView>(R.id.stv_focus).isVisible = true
                if (!TextUtils.isEmpty(item.remark)) {
                    setText(R.id.tv_content, item.remark)
                } else {
                    setText(R.id.tv_content, "")
                }
            } else {
                holder.getView<ShapeTextView>(R.id.stv_focus).isVisible = false
                setText(
                    R.id.tv_content,
                    "来关注你啦\n" + TimeUtils.getFriendlyTimeSpanByNow(item.createTime)
                )
            }

            loadImage(item.avatar, holder.getView<SelectableRoundedImageView>(R.id.siv_header))
//            Glide.with(context)
//                .load(item.avatar)
//                .placeholder(R.mipmap.image_zanwei)
//                .into(holder.getView<SelectableRoundedImageView>(R.id.siv_header))

            holder.itemView.setOnClickListener {
                val intent = Intent(context, LookUserDetailActivity2::class.java)
                if (type == 1){
                    intent.putExtra(IntentExtra.STR_TARGET_ID, item.followerUserId.toString())
                }else {
                    intent.putExtra(IntentExtra.STR_TARGET_ID, item.dyUserId.toString())
                }
                intent.putExtra("isContact", "1")
                context.startActivity(intent)
            }
        }
    }

}